home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_300
/
312_01
/
aincdep.awk
< prev
next >
Wrap
Text File
|
1990-04-21
|
13KB
|
283 lines
# HEADER: ;
# TITLE: Makefile dependency generator;
# DATE: 09/28/1989;
# VERSION: 1.2;
# DESCRIPTION: "An AWK program which finds included files in an assembly
# language source file and builds a dependency list. This
# dependency list is a component of a make-file. The list
# consists of the source file name followed by a colon and
# then all of the files which it includes (and also
# those which are included by the included files, &c.)
# The last item is a compile-command.";
#
# KEYWORDS: Makefile, make, include, dependency generator;
# SYSTEM: MS-DOS, UNIX;
# WARNINGS: "This is for Intel's assembler, not MASM.
# Doesn't handle directory names embedded within
# $include(here). Doesn't handle preprocessor $if.. blocks
# or $include statements which are "commented out."
# PolyAwk will generate false matches to lines
# beginning with non-ASCII (i.e. 128..256) chars."
# Filenames are case sensitive.";
# FILENAME: AINCDEP.AWK;
# SEE-ALSO: TLR2MAK.AWK, CF2MAK.AWK, CINCDEP.AWK, LBI2MAK.AWK;
# AUTHORS: James Yehle;
# COMPILERS: PolyAWK, Mortice Kern AWK, Rob Duff's PC-AWK 2.0,
# In any case, must be 1985 awk (not 1977);
# ============================================================================
#
# aincdep.awk Last modified Sep 28, 1989 22:31
#
# Scans an assembly source file for all "$include" dependencies
# This scanning process involves all nested include files, too.
#
# Usage is:
# awk -f [path]aincdep.awk [path]src_file.c objname=[path]filename
# cc=assemble_comd ccf=[p][n][e] [>[path]outfile]
# Pathnames must contain trailing separator, e.g. "s:asm\inc\"
# Order of command-line parameters (save for "-f ..."
# and srcfile.c) is irrelevant, but identifiers must be in lower case.
# "src_file.asm" may be replaced by special "__NOFILE__"
# cc is the assembly command
# ccf controls whether directory path (p) precedes filename in
# the assemble command line, and whether extension is added (e)
#
# Output is:
# [path]src_file.obj: [path]src_file[.ext] [path]included_file1 linecont
# [path]included_file2 [path]included_file3 ...
# <\t>comd [path]src_file[.ext]
# <\n>
# For __NOFILE__, output is:
# [path]src_file.obj:
# <\n>
# <\n>
#
# Jim Yehle
#
# . . . Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . .
#
# 1.2 Sep 10 89 JRY Added legal-filename-char regular expression
# 1.1 Aug 17 89 JRY Added add_fnexist option (as internal directive)
# If an included file can't be found, aincdep now
# beeps and prints an error to CO, then continues
# without scanning the file for nested inclusions.
# (It adds it to the dependency list.)
# Also added an optimization: if addfile() sees
# that a file is already in the list, then it has
# already been scanned, so it isn't done again.
# Added "verbose" CO output as debug level 1.
# 1.0 Jul 22 89 JRY Made aincdep for PL/M files; adapted from
# C dependency scanner cincdep.awk.
# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
#
# Notes about this program:
# It assumes Intel ASM286 assembler syntax
# It doesn't make any attempt to switch out $If() Then (...) Fi blocks.
# It is powerless to cover files $Included in the assembler's command-line
# It has no facilities for an include-file directory to be specified
# (since iRMX's assembler has none)
#
# Here are the syntax rules for $Include() (or $IC()):
# Control lines begin with $ in column 1
# and end with or end-of-line or a semicolon before end-of-line
# Multiple controls (immediately) follow the $, separated by space/tabs
# Only one "include" control is allowed per line
#
# What I can't deal with:
# "include(...)" as a parameter within some other control
# e.g. "title 'include(blah)' "
# ============================================================================
#
BEGIN {
co = "CON" # Console-out: MS-DOS "CON", iRMX ":co:", unix "/dev/tty"
linecont = " \\" # Line-continuation EOL char: snake " /", unix make "\\"
debug = 0 # 0=off, 1=verbose, 2=main-level debug, 3= adds functions
use_fnexist = 1 # Add nonexistent header files to dependency list?
fname_chars = "[^\\\\ :]" # Any single legal char in a file name.
# (Must exclude directory path separator character! (DOS \, UNIX /) )
printf( "aincdep.awk ASMx86 $include dependency scanner v 1.2") >co
objfile = get_cl_param( "objname=", 0)
if (debug) printf( "objfile = '%s'\n", objfile) > co
cc = get_cl_param( "cc=", 0)
if (debug) printf( "cc = '%s'\n", cc) > co
ccf = get_cl_param( "ccf=", 0)
if (debug) printf( "ccf = '%s'\n", ccf) > co
if (ARGV[1] == "__NOFILE__") {
if (debug)
printf( "\n__NOFILE__: Empty dependency list generated.\n") > co
else
printf( " (of __NOFILE__)\n") > co
exit # Hop to END; srcfile is still an empty string & flist is empty
}
# 1st in list of ARGV[]'s is source file (FILENAME not set in BEGIN section)
fullsrcfile = ARGV[1]
# Split primary source file name into Path, Name, and Extension components
split_filename( fullsrcfile, srcfile, fname_chars)
if (debug)
printf( "\n Scanning primary source file '%s%s%s'\n",
srcfile["path"], srcfile["name"], srcfile["ext"]) > co
else
printf( " (of %s%s%s)\n",
srcfile["path"], srcfile["name"], srcfile["ext"]) > co
if (debug) printf( "srcfile[\"path\"] = \"%s\"\n", srcfile["path"]) > co
if (debug) printf( "srcfile[\"name\"] = \"%s\"\n", srcfile["name"]) > co
if (debug) printf( "srcfile[\"ext\"] = \"%s\"\n", srcfile["ext"]) > co
}
#
/^\$[^;]*[Ii][Nn][Cc][Ll][Uu][Dd][Ee][ \t]*\(.*\)/ {
if (debug) printf( "$include control line: $0='%s'\n", $0) > co
extract_include_filename() # into $1
if (debug) printf( " extracted filename = '%s'\n", $1) > co
# Check for nested inclusions by scanning included file for $Include's
scanfile( $1)
}
/^\$[^;]*[Ii][Cc][ \t]*\(.*\)/ {
if (debug) printf( "$include control line: $0='%s'\n", $0) > co
extract_ic_filename() # into $1
if (debug) printf( " extracted filename = '%s'\n", $1) > co
# Check for nested inclusions by scanning included file for $Include's
scanfile( $1)
}
# Produce the dependency list printout
END {
# Print primary (object) file name before list (left of colon),
# Print primary source file name (*.c) as first item in list.
printf( "%s: %s", objfile, fullsrcfile )
if (debug) printf( "%s: %s", objfile, fullsrcfile) >co
linelen = length(objfile) + 2 + length(fullsrcfile)
for (i=1; i in flist; i++) {
# If line will be too long, put out a line-continuation char and newline
if (linelen + 1 + length(flist[i]) + length(linecont) > 79) {
printf( "%s\n", linecont)
if (debug) printf( "%s\n", linecont) >co
# On the new line, tab out to underneath the first included file name
for (linelen=0; linelen<length(objfile)+1; ++linelen) {
printf(" ")
if (debug) printf(" ") >co
}
}
printf( " %s", flist[i] )
if (debug) printf( " %s", flist[i] ) >co
linelen += length(flist[i]) + 1
}
# Build the assemble command line's only parameter: the filename
# depending on options specified in ccf command-line param
assemble_comd_filename = sprintf( "%s%s%s",
ccf ~ /[Pp]/? srcfile["path"] : "",